<?php
defined('_JEXEC') or die('Restricted access');	
define('IG_ADMIN_ROOT', JPATH_ADMINISTRATOR.DS.'components'.DS.'com_igallery');
define('IG_FRONTEND_ROOT', JPATH_SITE.DS.'components'.DS.'com_igallery');


$filesToDelete = array();
$filesToDelete[] = IG_ADMIN_ROOT.DS.'config.xml';
$filesToDelete[] = IG_ADMIN_ROOT.DS.'views'.DS.'igphoto'.DS.'tmpl'.DS.'html5upload.php';
$filesToDelete[] = IG_ADMIN_ROOT.DS.'views'.DS.'igphoto'.DS.'tmpl'.DS.'swfupload.php';
$filesToDelete[] = IG_ADMIN_ROOT.DS.'views'.DS.'igphoto'.DS.'tmpl'.DS.'swfupload_rs.php';

$filesToDelete[] = IG_FRONTEND_ROOT.DS.'views'.DS.'igphoto'.DS.'tmpl'.DS.'html5upload.php';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'views'.DS.'igphoto'.DS.'tmpl'.DS.'swfupload.php';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'views'.DS.'igphoto'.DS.'tmpl'.DS.'swfupload_rs.php';

$filesToDelete[] = IG_FRONTEND_ROOT.DS.'views'.DS.'igcategory'.DS.'tmpl'.DS.'default_menuslider.php';

$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'ico-arrow-bottom.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'ico-arrow-left.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'ico-arrow-right.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'ico-arrow-top.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'down_arrow.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'left_arrow.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'right_arrow.gif';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'images'.DS.'up_arrow.gif';

$filesToDelete[] = IG_FRONTEND_ROOT.DS.'javascript'.DS.'category.js';
$filesToDelete[] = IG_FRONTEND_ROOT.DS.'javascript'.DS.'categoryTree.js';

for($i=0; $i<count($filesToDelete); $i++)
{
    if(JFile::exists($filesToDelete[$i]))
    {
        if( !JFile::delete($filesToDelete[$i]) )
        {
            echo 'The Unused File (from version 2.5): '.$filesToDelete[$i]. ' could not be removed, 
            please remove it manually <br />';
        }
    }
}

$foldersToDelete = array();
$foldersToDelete[] = IG_ADMIN_ROOT.DS.'lib'.DS.'swfupload';
   
for($i=0; $i<count($foldersToDelete); $i++)
{
    if(JFolder::exists($foldersToDelete[$i]))
    {
        if( !JFolder::delete($foldersToDelete[$i]) )
        {
            echo 'The Unused Folder (from version 2.1): '.$foldersToDelete[$i]. ' could not be removed, 
            please remove it manually <br />';
        }
    }
}

$queries = array();
$queries[] = "ALTER TABLE `#__igallery` ADD `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP";
$queries[] = "ALTER TABLE `#__igallery` ADD `moderate` int(1) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery` ADD `hits` int(11) NOT NULL";

$queries[] = "ALTER TABLE `#__igallery_img` ADD `moderate` int(1) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_img` ADD `rotation` int(4) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_img` ADD `hits` int(11) NOT NULL";
$queries[] = "ALTER TABLE `#__igallery_img` ADD `menu_image` int(1) NOT NULL DEFAULT '0'";

$queries[] = "ALTER TABLE `#__igallery_comments` ADD `moderate` int(1) NOT NULL DEFAULT '1'";

$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `access`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `menu_access`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `ct_view`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `ct_level_width`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `ct_area_width`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `ct_area_height`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `ct_scroll_speed`";
$queries[] = "ALTER TABLE `#__igallery_profiles` DROP `ct_scroll_area`";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_menu` varchar(255) NOT NULL DEFAULT '2'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_display` varchar(255) NOT NULL DEFAULT '2'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_view` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_edit` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_delete` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_publish` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_cat_order` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_upload` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_photo_view` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_photo_edit` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_photo_del` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_photo_publish` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `acl_photo_ordering` varchar(255) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `show_cat_title` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `crop_menu` int(1) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `crop_main` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `crop_lbox` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `menu_pagination` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `menu_pagination_amount` int(3) NOT NULL DEFAULT '20'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `round_large` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `round_thumb` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `round_fill` varchar(12) NOT NULL DEFAULT 'FFFFFF'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `round_menu` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `refresh_mode` varchar(24) NOT NULL DEFAULT 'javascript'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `show_tags` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `lbox_show_tags` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `watermark_text` varchar(255) NOT NULL";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `watermark_text_color` varchar(24) NOT NULL DEFAULT '255,255,255'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `watermark_text_size` int(11) NOT NULL DEFAULT '16'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `share_facebook` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `lbox_share_facebook` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `menu_image_defaults` int(1) NOT NULL DEFAULT '1'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `report_image` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `lbox_report_image` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `thumb_pagination` int(1) NOT NULL DEFAULT '0'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `thumb_pagination_amount` int(4) NOT NULL DEFAULT '20'";
$queries[] = "ALTER TABLE `#__igallery_profiles` ADD `lbox_scalable` int(1) NOT NULL DEFAULT '0'";


for($i=0;$i<count($queries); $i++)
{
	$db->setQuery($queries[$i]);
	$db->query();
}
    